<?php
/*
 *author:Yangligao
 *Date:2013-9-30
 */

require '../../Config.php';

$flag = $_GET['flag'];
$proModel = new FoodModel();
if($flag == 'display'){
	$food_id = $_GET['food_id'];
	$eachProData = $proModel->food_select('*',"where food_id=$food_id");
	
	//将生产日期拆分成year  month   day
	$arr1 = explode('-', date("Y-m-d",$eachProData[0]['food_producttime']));
	$eachProData[0]['year1'] = $arr1[0];
	$eachProData[0]['month1'] = $arr1[1];
	$eachProData[0]['day1'] = $arr1[2];
	
	//将过期日期拆分成year  month   day
	$arr2 = explode('-', date("Y-m-d",$eachProData[0]['food_enddate']));
	$eachProData[0]['year2'] = $arr2[0];
	$eachProData[0]['month2'] = $arr2[1];
	$eachProData[0]['day2'] = $arr2[2];	
	
	//去掉原来的生产日期和过期日期 ，保证数据的清洁
	unset($eachProData[0]['food_enddate']);
	unset($eachProData[0]['food_producttime']);

	$smarty->assign('eachProData',$eachProData[0]);
	
	//查出供应商的名字 id
	$joincpModel = new JoinCpModel();
	
	$cpData = $joincpModel->joincp_select("cp_name,cp_id");
	$smarty->assign('cpData',$cpData);
	
	$smarty->display('Admin/ProM/proupdate.html');
}else if($flag == 'proupdate'){
	unset($_POST['x']);
	unset($_POST['y']);
	//生产日期更新，拼接日期
	$_POST['food_producttime'] = strtotime($_POST['year1']."-".$_POST['month1']."-".$_POST['day1']);
	$_POST['food_enddate'] = strtotime($_POST['year2']."-".$_POST['month2']."-".$_POST['day2']);
	//去掉原来的时间
	unset($_POST['year1']);
	unset($_POST['month1']);
	unset($_POST['day1']);
	unset($_POST['year2']);
	unset($_POST['month2']);
	unset($_POST['day2']);
	//更新添加日期
	$_POST['food_addtime'] = time();
	if(($_FILES['pic']['name'] !='') && ($_FILES['pic']['error']) == 0){
		$upload = new Upload();
		$picPath = $upload->savePic('../Upload/foodPic');	
		$_POST['food_pic'] = $picPath;
	}
	$res = $proModel->food_update($_POST);
	if($res){
		jump('操作成功！', $_SERVER['HTTP_REFERER']);
	}else{
		alertInfo('操作失败！！', $_SERVER['HTTP_REFERER']);
	}
}
?>
